import "./app.css";
import App from "./App.svelte";

import { getAllMenu } from "./service";

export class HelpWebModule {
  systemId = "";
  appInstance = null;
  constructor({
    systemId,
    slicePoint = 3,
  }: {
    systemId: string;
    slicePoint?: number;
  }) {
    this.systemId = systemId;
    if (!systemId) {
      return;
    }
    getAllMenu(systemId).then((resourceList) => {
      if (!this.appInstance) {
        this.appInstance = new App({
          target: document.body,
          props: {
            systemId,
            resourceList,
            slicePoint,
          },
        });
      }
    });
  }
  setMenuCode(menuCode?: string) {
    if (this.appInstance && this.appInstance.setMenuCode) {
      this.appInstance.setMenuCode();
    }
  }
}

// if (import.meta.env.MODE === "development") {
//   const helpWebModule = new HelpWebModule({
//     systemId: "82522199059099734",
//     slicePoint: 0,
//   });

//   helpWebModule.setMenuCode("");
// }

// window.document.getElementById("btn").addEventListener("click", () => {
//   helpWebModule.setMenuCode("");
// });
// export default app;
